home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.3 KB | 61 lines | [TEXT/CWIE] |
- // FiniteQueueBase.cp
-
- #ifndef FiniteQueueBase_h
- #include "FiniteQueueBase.h"
- #endif
- #ifndef Assert_h
- #include "Assert.h"
- #endif
-
- FiniteQueueBase::FiniteQueueBase( void *theStart,
- uint32 theLength,
- uint32 theElementSize )
- : start( static_cast<uint8 *>(theStart) ),
- end( static_cast<uint8 *>(theStart) + theLength * theElementSize ),
- elementSize( theElementSize ),
- length( theLength ),
- allocated( 0 ),
- allocateNext( static_cast<uint8 *>(theStart) ),
- disposeNext( static_cast<uint8 *>(theStart) )
- {
- Assert( CanMultiply( theLength, theElementSize ) )
- }
-
- void *FiniteQueueBase::Allocate( uint32 size )
- {
- Assert( size == elementSize );
- Assert( !Full() );
-
- Assert( allocateNext >= start );
- Assert( allocateNext < end );
- Assert( ( allocateNext - start ) % elementSize == 0 );
-
- void *result = allocateNext;
-
- allocateNext += elementSize;
- Assert( allocateNext <= end );
- if ( allocateNext >= end )
- allocateNext = start;
-
- allocated++;
-
- return result;
- }
-
- void FiniteQueueBase::Release( void *p )
- {
- Assert( !IsEmpty() );
- Assert( p == disposeNext );
-
- Assert( disposeNext >= start );
- Assert( disposeNext < end );
- Assert( ( disposeNext - start ) % elementSize == 0 );
-
- disposeNext += elementSize;
- Assert( disposeNext <= end );
- if ( disposeNext >= end )
- disposeNext = start;
-
- allocated--;
- }
-